package com.aster.common.base;


import com.aster.common.constants.CommonConstants;
import com.aster.common.dto.UserToken;
import com.aster.common.exception.ServiceException;
import com.aster.common.utils.JwtUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    public UserToken getUserToken(HttpServletRequest headers) throws ServiceException {
        try{
            String accessToken = headers.getHeader(CommonConstants.CONTEXT_TOKEN);
            UserToken userToken = JwtUtils.getInfoFromToken(accessToken);
            return userToken;
        }catch (Exception ex){
            throw new ServiceException(10000,ex.getMessage());
        }
    }
}
